Skip to content

Fix GH-23120: DOMNode::isEqualNode stack overflow on deeply nested trees - #23140

Merged
LamentXU123 merged 4 commits into
php:PHP-8.4from
LamentXU123:dom-fix-overflow
Aug 8, 2026
Merged

Fix GH-23120: DOMNode::isEqualNode stack overflow on deeply nested trees#23140
LamentXU123 merged 4 commits into
php:PHP-8.4from
LamentXU123:dom-fix-overflow

Conversation

@LamentXU123

Copy link
Copy Markdown
Member

DOMNode::isEqualNode() recursively compared ordered child lists.

Compare each node without descending into its children first to solve this and we walk both subtrees in tree order to compare descendants iteratively.

Fix GH-23120

@devnexen

devnexen commented Aug 8, 2026

Copy link
Copy Markdown
Member

I would rather prefer you control the stack limit ; also, for once, the CI arm issue is very related (timeout?).

Comment thread ext/dom/node.c Outdated
ZEND_ASSERT(other != NULL);

if (UNEXPECTED(php_dom_node_is_equal_node_check_stack_limit())) {
zend_throw_error(NULL, "Maximum call stack size reached. Infinite recursion?");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it needs to be gated with the exception global.

Comment thread ext/dom/node.c Outdated

if (UNEXPECTED(php_dom_node_is_equal_node_check_stack_limit())) {
if (!EG(exception)) {
zend_throw_error(NULL, "Maximum call stack size reached. Infinite recursion?");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can't be infinite recursion because a tree is an acyclic graph

Suggested change
zend_throw_error(NULL, "Maximum call stack size reached. Infinite recursion?");
zend_throw_error(NULL, "Maximum call stack size reached.");

@LamentXU123 LamentXU123 Aug 8, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is correct! I copy-paste this message from the last fix #23127 and I overlook this. Thx

@LamentXU123
LamentXU123 merged commit c4c356a into php:PHP-8.4 Aug 8, 2026
18 checks passed
LamentXU123 added a commit that referenced this pull request Aug 8, 2026
* PHP-8.5:
  Fix GH-23120: DOMNode::isEqualNode stack overflow on deeply nested trees (#23140)
NickSdot pushed a commit to NickSdot/php__php-src that referenced this pull request Aug 8, 2026
* PHP-8.4:
  Fix phpGH-23120: DOMNode::isEqualNode stack overflow on deeply nested trees (php#23140)
@iluuu1994

Copy link
Copy Markdown
Member

@LamentXU123

Copy link
Copy Markdown
Member Author

ffs, I didn't expect stack depth on every platform to be that huge.
Ok lets use Fibers to test this... I am working on it now. Thanks.

@devnexen

devnexen commented Aug 9, 2026

Copy link
Copy Markdown
Member

@shivammathur had fixed later on here I believe.

@iluuu1994

Copy link
Copy Markdown
Member

@devnexen Ah thanks, I missed that there was another commit.

@LamentXU123

LamentXU123 commented Aug 9, 2026

Copy link
Copy Markdown
Member Author

I see, but I think this can still be improved..? I suggest to use Fibers on this because we want our test to pass on extremely extreme platforms.

something like

fiber.stack_size=256K

and call isEqualSize in Fibers.
wdyt @devnexen ?

@devnexen

devnexen commented Aug 9, 2026

Copy link
Copy Markdown
Member

That seems overengineered to me.

@LamentXU123

Copy link
Copy Markdown
Member Author

Understandable :P
At least I can't imagine when zend.max_allowed_stack_size=256K could fails. This should be robust enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants